import time
import pyautogui
import keyboard as kb

class Mouse:
    def __init__(self):
        # 设置pyautogui的安全设置
        self.running = False
        pyautogui.FAILSAFE = True
        pyautogui.PAUSE = 0.1
    
    def move_to(self, x, y, duration=0.5):
        """移动鼠标到指定坐标"""
        pyautogui.moveTo(x, y, duration=duration)
    
    def click(self, button='left'):
        """点击鼠标"""
        pyautogui.click(button=button)
    
    def double_click(self, button='left'):
        """双击鼠标"""
        pyautogui.doubleClick(button=button)
    
    def always_click(self, button='left', interval=0.5):
        self.running = True
        while self.running:
            self.click(button)
            time.sleep(interval)
    
    def stop(self):
        self.running = False
    
    def drag_to(self, x, y, duration=0.5):
        """拖动鼠标到指定位置"""
        pyautogui.dragTo(x, y, duration=duration)
    
    def get_position(self):
        """获取当前鼠标位置"""
        return pyautogui.position()
    
    def scroll(self, clicks):
        """滚动鼠标滚轮"""
        pyautogui.scroll(clicks)

class Keyboard:
    def __init__(self):
        pass
    
    def press_key(self, key):
        """按下单个按键"""
        kb.press(key)
    
    def release_key(self, key):
        """释放按键"""
        kb.release(key)
    
    def press_and_release(self, key):
        """按下并释放按键"""
        kb.press_and_release(key)
    
    def write(self, text):
        """输入文本"""
        kb.write(text)
    
    def hotkey(self, *keys):
        """组合键"""
        kb.press_and_release('+'.join(keys))
    
    def is_pressed(self, key):
        """检查按键是否被按下"""
        return kb.is_pressed(key)
    
    def wait(self, key):
        """等待按键被按下"""
        kb.wait(key)

# 使用示例
if __name__ == "__main__":
    mouse = Mouse()
    keyboard = Keyboard()
    mouse.click('right')
